import json
import time
import requests
from Base.BaseSetting import url_path
from Base.PublicFunction import Requst


class Stu_manage:
    def __init__(self):
        self.session = Requst.get_session()
        self.url = url_path + '/WoniuBoss4.0'

    def queryClass(self, pageSize, pageIndex, regionId, openStatus):  # 查询已有班级信息 01已开班 02未开班
        headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
        data = f'pageSize={pageSize}&pageIndex={pageIndex}&regionId={regionId}&openStatus={openStatus}'
        url = self.url + '/stuClass/queryClass'
        content = self.session.post(url=url, headers=headers, data=data, )
        res = json.loads(content.text)
        return res

    def addClass(self, class_no, opening_time, headmaster_id):  # 新增班级
        headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
        body = f'c.class_no={class_no}&c.orientation=%E6%B5%8B%E8%AF%95&c.opening_time={opening_time}&c.class_headmaster_id={headmaster_id}'
        url = self.url + '/stuClass/saveAddClass'
        content = self.session.post(url=url, headers=headers, data=body.encode('UTF-8'))
        return content.text

    def queryLeave(self, pageSize, pageIndex, leaveStatus, regionId):  # 查询请假学生信息
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        data = f'pageSize={pageSize}&pageIndex={pageIndex}&leaveStatus={leaveStatus}&stuName=%E9%99%88%E9%9B%AA&regionId={regionId}'
        url = self.url + '/stuLeave/queryLeave'
        content = self.session.post(url=url, headers=headers, data=data)
        res = json.loads(content.text)
        return res

    def addLeave(self, student_id, start_time, end_time, days, leave_count):  # 新增学员请假信息
        headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}
        data = f'sl.student_id={student_id}&sl.start_time={start_time}&sl.end_time={end_time}&sl.leave_type=01&sl.days={days}&stuName=%E9%99%88%E9%9B%AA&sl.leave_count={leave_count}&sl.reason=%E8%AF%A5%E5%AD%A6%E7%94%9F%E8%AF%B7%E5%81%87%E5%8E%BB%E5%8F%82%E5%8A%A0%E9%9D%A2%E8%AF%95&sl.comment='
        url = self.url + '/stuLeave/saveLeave'
        content = self.session.post(url=url, headers=headers, data=data)
        return content.text

    def queryStuByInfo(self, pageSize, pageIndex, stuClass, regionId):  # 查询学生转班信息
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}
        data = f'pageSize={pageSize}&pageIndex={pageIndex}&stuName=%E6%9B%B9%E5%8D%8E&stuClass={stuClass}&stuStatus=&regionId={regionId}'
        url = self.url + '/studentInfo/queryStuByInfo'
        content = self.session.post(url=url, headers=headers, data=data)
        res = json.loads(content.text)
        return res


if __name__ == '__main__':
    w = Stu_manage()
    '''查询已有班级信息'''
    # res = w.queryClass(10,1,1,'01')
    # print(res)
    '''新增班级'''
    # res = w.addClass('WNCDC',2020-11-26,5)
    # print(res)
    '''查询请假学生信息'''
    # res = w.queryLeave(10,1,'01',1)
    # print(res)
    '''新增学员请假信息'''
    # res = w.addLeave(3354,'2020-11-18','2020-12-04',5,'01')
    # print(res)
    '''查询学生转班信息'''
    # res = w.queryStuByInfo(10,1,'WN00000',1)
    # print(res)
